#!/usr/bin/env python

class Structure:
    def __init__(self):
        #example init, must be written over to get anything useful out of this
        self.masses = []
        self.constraints = []
        
        self.structure = {}
        self.getStructure()
        
        self.fix = 0.1
    
    def getCenter(self):
        center = [0, 0]
        for mass in self.masses:
            center[0] += mass.x
            center[1] += mass.y
        center[0] /= len(self.masses)
        center[1] /= len(self.masses)
        return center
    
    def getStructure(self):
        """Call this once you're done adding masses to a structure"""
        center = self.getCenter()
        for mass in self.masses:
            self.structure[mass] = [mass.x - center[0], mass.y - center[1]]
    
    def handleStructure(self):
        """Makes the structure retain its form"""
        center = self.getCenter()
        
        for mass in self.masses:
            idealPos = center[0] + self.structure[mass][0], center[1] + self.structure[mass][1]
            
            fixValue = self.fix / mass.weight
            mass.x = idealPos[0] * (fixValue) + mass.x * (1 - fixValue)
            mass.y = idealPos[1] * (fixValue) + mass.y * (1 - fixValue)